<?php

/**
 * @author Djordje Zeljic
 * Date: May 27, 2010 4:58:41 PM
 */
class accounts_m extends Model {

    function accounts_m() {
        parent::Model();
    }// construct of accounts_m

    function create() {

    }

    function read($id, $cascaderead = FALSE) {
        if($cascaderead == TRUE) {
            return $this->db->select('*')
                    ->from('accounts')
                    ->join('customers','customers.id = accounts.customerid','left')
                    ->join('countries','countries.ccode = customers.countrycode','left')
                    ->where('accounts.accountNumber',$id)
                    ->get()
                    ->row_array();
        }else {
            return $this->db->where('id',$id)->get()->row_array();
        }
    }

    function readAll($cascaderead = FALSE) {
        if($cascaderead == TRUE) {
            return $this->db->select('*')
                    ->from('accounts')
                    ->join('customers','customers.id = accounts.customerid','left')
                    ->join('countries','countries.ccode = customers.countrycode','left')
                    ->order_by('accounts.accountNumber','desc')
                    ->get()
                    ->result_array();
        }else {
            return $this->db->select('*')
                    ->from('accounts')
                    ->order_by('accounts.accountNumber','desc')
                    ->get('accounts')
                    ->result_array();
        }
    }

    function update() {

    }

    function delete() {

    }

}
?>